package com.android.djlmapp.adapter.kaika;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.model.kaika.KaiKaHomeInfo;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

public class KaiKaAdapter extends BaseAdapter {
    private ArrayList<KaiKaHomeInfo.ActionBean> list = new ArrayList();
    private Context context;
    private int type; //1代表开卡,2代表宽带
    // 宽带首页
    private static final int[] kdIcons = {R.mipmap.kd_dkd, R.mipmap.kd_jzkd, R.mipmap.kd_zhwj};
    private static final String[] kdNames = {"单宽带", "加装宽带", "智慧沃家"};
    private static final String[] kdcontents = {"在线申请 极速办理", "加装宽带 方便快捷", "百兆宽带 畅享极速"};

    // 开卡首页
    private static final int[] kkIcons = {R.mipmap.kk_dkyw, R.mipmap.kk_jtyw, R.mipmap.kk_hyjyw,
            R.mipmap.kk_ckjh, R.mipmap.kk_wxgh};
    private static final String[] kkNames = {"单卡业务", "集团业务", "合约机业务", "成卡激活", "无线固话"};
    private static final String[] kkcontents = {"办理手机开卡,方便快捷", "集团业务办理", "0利息0首付轻松买手机"
            , "成卡激活,快速开卡", "成卡办理,快速受理"};

    public KaiKaAdapter(Context context) {
        this.context = context;
    }

    public void setData(int type, ArrayList<KaiKaHomeInfo.ActionBean> list) {
        this.type = type;
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list.size() > 0) {
            return list.size();
        } else {
            if (type == 1) {
                return kkIcons.length;
            } else if (type == 2) {
                return kdIcons.length;
            } else {
                return 0;
            }
        }
    }

    @Override
    public KaiKaHomeInfo.ActionBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        View view = View.inflate(context, R.layout.item_kaika_layout, null);

        ImageView iv_icon_kaika = view.findViewById(R.id.iv_icon_kaika);
        TextView tv_title_kaika = view.findViewById(R.id.tv_title_kaika);
        TextView tv_title_content = view.findViewById(R.id.tv_title_content);
        View kkLine = view.findViewById(R.id.kk_line);
        if (list.size() > 0) {
            if (position == (list.size() - 1)) {
                kkLine.setVisibility(View.GONE);
            }
            String url = getItem(position).getIcon();

            Glide.with(context).load(url).into(iv_icon_kaika);
            tv_title_kaika.setText(getItem(position).getTitle());
            tv_title_content.setText(getItem(position).getInfo());
        } else {
            if (type == 1) {
                Glide.with(context).load(kkIcons[position]).into(iv_icon_kaika);
                tv_title_kaika.setText(kkNames[position]);
                tv_title_content.setText(kkcontents[position]);
                if (position == (kkIcons.length - 1)) {
                    kkLine.setVisibility(View.GONE);
                }
            } else if (type == 2) {
                if (position == (kdIcons.length - 1)) {
                    kkLine.setVisibility(View.GONE);
                }
                Glide.with(context).load(kdIcons[position]).into(iv_icon_kaika);
                tv_title_kaika.setText(kdNames[position]);
                tv_title_content.setText(kdcontents[position]);
            }
        }
        return view;
    }
}
